{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.数组\n",
    "\n",
    "说句实话，数组这方面的更新暂时没看到有太大意义\n",
    "\n",
    "### includes\n",
    "\n",
    "`includes`：是否包含某个元素\n",
    "\n",
    "```javascript\n",
    "let arr = [1, 2, 3, 4, 5, 6, 7];\n",
    "\n",
    "// 数组 includes：是否包含某个元素\n",
    "console.log(arr.includes(3)); // true\n",
    "console.log(arr.includes(\"3\")); // false\n",
    "```\n",
    "\n",
    "### for of\n",
    "\n",
    "`for of`：遍历可迭代对象（**现在**其实用处不是很大，只是跟`Python、Net、Java`他们语法靠近）\n",
    "\n",
    "#### 数组测试\n",
    "\n",
    "```javascript\n",
    "let arr = [1, 2, 3, 4, 5, 6, 7];\n",
    "\n",
    "// for in循环的是key（数组对应的是index）\n",
    "for (let i in arr) {\n",
    "    console.log(i); // 0 1 2 3 4 5 6\n",
    "}\n",
    "\n",
    "console.log(\"------------\");\n",
    "\n",
    "// for of循环的是value\n",
    "for (let i of arr) {\n",
    "    console.log(i); // 1 2 3 4 5 6 7\n",
    "}\n",
    "```\n",
    "\n",
    "#### json测试\n",
    "\n",
    "`json`对象是一个不可迭代的对象（`for of`只能遍历可迭代对象）\n",
    "\n",
    "```javascript\n",
    "let json = {name:\"dnt\",age:\"25\",wechat:\"dotnetcrazy\"};\n",
    "\n",
    "// for in 还是遍历的是key\n",
    "for(let i in json){\n",
    "    console.log(i); // name age wechat\n",
    "}\n",
    "\n",
    "// PS：获取值\n",
    "for(let i in json){\n",
    "    console.log(json[i]); // dnt 25 dotnetcrazy\n",
    "}\n",
    "\n",
    "\n",
    "// json对象是一个不可迭代的对象（for of只能遍历可迭代对象）\n",
    "for(let i of json){\n",
    "    console.log(i); // json is not iterable\n",
    "}\n",
    "```\n",
    "\n",
    "#### 新方式\n",
    "\n",
    "仿照Python，有了一个数组的遍历新方式：\n",
    "1. keys()：key集合\n",
    "2. values()：value集合\n",
    "3. **`entries()`：key-value集合**\n",
    "\n",
    "```javascript\n",
    "let nums = [1, 2, 3, 4, 5, 6, 7];\n",
    "\n",
    "// console.log(nums)\n",
    "for (let key of nums.keys()) {\n",
    "    console.log(key);\n",
    "}\n",
    "for (let value of nums.values()) {\n",
    "    console.log(value);\n",
    "}\n",
    "\n",
    "// 遍历key，value\n",
    "for (let [key, value] of nums.entries()) {\n",
    "    console.log(key, value)\n",
    "}\n",
    "```\n",
    "PS：总感觉有点业余，估计过段时间会支持json\n",
    "\n",
    "看看Python对应的遍历方式：(字典：`dict`)\n",
    "```py\n",
    "user = {\"name\": \"dnt\", \"age\": 25, \"wechat\": \"dotnetcrazy\"}\n",
    "\n",
    "for key in user.keys():\n",
    "    print(key)  # name age wechat\n",
    "\n",
    "for value in user.values():\n",
    "    print(value)  # dnt 25 dotnetcrazy\n",
    "\n",
    "for key, value in user.items():\n",
    "    print(key, value)  # name dnt  age 25  wechat dotnetcrazy\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.运算符\n",
    "\n",
    "添加了一个幂运算符：`**`\n",
    "\n",
    "看一个案例：(用法和Python一样)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "let a = 3;\n",
    "a**2 // 3^2=9"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.字符串\n",
    "\n",
    "添加了2个填充的方法：\n",
    "1. padStart\n",
    "2. padEnd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0000001325\n",
      "[1325      ]\n"
     ]
    }
   ],
   "source": [
    "let str = \"1325\";\n",
    "\n",
    "// 10个坑位，指定用0填充（默认用空格填充）\n",
    "let net_str = str.padStart(10, \"0\");\n",
    "console.log(net_str); // 0000001325\n",
    "\n",
    "// 默认用空格填充\n",
    "net_str = str.padEnd(10); // [1325      ]\n",
    "console.log('[' + net_str + ']');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "看看Python的相关方法：\n",
    "```py\n",
    "# 格式系列：lstrip（去除左边空格）,rstrip（去除右边空格）,strip（去除两边空格\n",
    "strip_str = \" I Have a Dream \"\n",
    "\n",
    "print(\"[\"+strip_str.strip()+\"]\")\n",
    "print(\"[\"+strip_str.lstrip()+\"]\")\n",
    "print(\"[\"+strip_str.rstrip()+\"]\")\n",
    "\n",
    "# 美化输出系列：ljust,rjust,center\n",
    "test_str = \"ABCDabcdefacddbdf\"\n",
    "\n",
    "print(\"[\"+test_str.ljust(50)+\"]\")\n",
    "print(\"[\"+test_str.rjust(50)+\"]\")\n",
    "print(\"[\"+test_str.center(50)+\"]\")\n",
    "```\n",
    "输出：\n",
    "```\n",
    "[I Have a Dream]\n",
    "[I Have a Dream ]\n",
    "[ I Have a Dream]\n",
    "[ABCDabcdefacddbdf                                 ]\n",
    "[                                 ABCDabcdefacddbdf]\n",
    "[                ABCDabcdefacddbdf                 ]\n",
    "```\n",
    "\n",
    "## 4.扩展\n",
    "\n",
    "ES6：http://www.ecma-international.org/ecma-262/6.0/index.html\n",
    "\n",
    "ES7：http://www.ecma-international.org/ecma-262/7.0/index.html\n",
    "\n",
    "ES8：http://www.ecma-international.org/ecma-262/8.0/index.html"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Javascript (Node.js)",
   "language": "javascript",
   "name": "javascript"
  },
  "language_info": {
   "file_extension": ".js",
   "mimetype": "application/javascript",
   "name": "javascript",
   "version": "8.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
